<template>
    <div class="header-wrapper">
        <header>

            <div class="nav">
                <div class="logo">
                    <a href="#">网易云音乐</a>
                </div>
                <div class="left">
                    <template v-for="(nav, index) in headerNavs" key="index">
                        <router-link class="f-tdn" v-if="nav.route" :class="currentRoute.includes(nav.route) ? 'active' : ''"
                            :to="{ path: nav.route }" @click="changStyle(nav.route)">
                            <em>{{ nav.name }}</em>
                            <sub v-show="currentRoute.includes(nav.route)" class="cor"></sub>
                        </router-link>
                        <a v-else :href="nav.link" class="f-tdn">{{ nav.name }}</a>
                    </template>
                </div>
                <div class="right">
                    <div class="search">
                        <div class="parent">
                            <input type="text" placeholder="音乐/视频/电台/用户">
                        </div>

                    </div>
                    <a href="#" class="creator-center-btn f-tdn">
                        创作者中心
                    </a>
                    <!-- <a href="#" class="login-btn">登陆</a> -->
                    <TopHead></TopHead>

                </div>
            </div>
        </header>
        <div class="sub-nav-up" v-if="!currentRoute.includes('/discover')"></div>

    </div>
</template>
<script setup>
import { useRoute, useRouter } from 'vue-router';
import { onMounted, ref } from 'vue';
import TopHead from './TopHead.vue';
import headerNavs from '../json_data/header_nav.json'
const $emit = defineEmits(['changeSubNav']);

const router = useRouter();
const route = useRoute();
let currentRoute = ref('');

router.isReady().then(() => {
    currentRoute.value = route.path;
})
const changStyle = (routeParam) => {
    currentRoute.value = routeParam;
    $emit("changeSubNav", routeParam);

}
</script>

<style lang="scss" scoped>
.header-wrapper {
    header {

        background-color: #242424;
       

        .nav {
            width: 1124px;
            height: 70px;
            margin: 0 auto;

            a {
                color: #ccc;
                font-size: 14px;
                display: block;
            }



            display: flex;
            align-items: center;

            .left {
                display: flex;

                height: 100%;
                line-height: 69px;

                a {
                    position: relative;

                    &:hover {

                        background-color: #000;
                        color: #fff;
                    }

                    &.active {
                        background-color: #000;
                        color: #fff;
                    }

                    .cor {
                        position: absolute;
                        display: block;
                        background-position: -226px 0;
                        width: 12px;
                        height: 7px;
                        left: 50%;
                        top: 64px;
                        margin-left: -7px;
                    }
                }

                >* {
                    padding: 0 16px;
                }

            }

            .right {

                .search {
                    background-position: 0 -99px;
                    background-color: #fff;
                    width: 158px;
                    height: 32px;
                    display: flex;
                    align-items: center;
                    border-radius: 32px;
                    box-sizing: border-box;

                    input {
                        background-color: transparent;
                        outline: 0;
                        border: 0;
                        margin-left: 9px;
                        width: 100%;

                    }


                }

                .creator-center-btn {
                    border: 1px solid #4f4f4f;
                    line-height: 33px;
                    border-radius: 20px;
                    margin: 12px;
                    text-align: center;
                    font-size: 12px;

                    &:hover {
                        color: #fff;
                        border: 1px solid #ccc;
                    }
                }

                .login-btn {
                    font-size: 12px;
                    color: #787878;

                    &:hover {
                        text-decoration: underline;
                    }
                }


                display: flex;
                align-items: center;
                margin-left: 20px;

                >* {
                    padding: 0 16px;
                }
            }


            .logo {
                width: 176px;
                height: 69px;

                a {
                    display: block;
                    width: 157px;
                    height: 100%;
                }

                background-position: 0px 0px;
                text-indent: -9999px;

            }

        }

    

    }

    .sub-nav-up {
            height: 5px;
            border-bottom: none;
            background-color: #C20C0C;
            border-bottom: 1px solid #a40011;
        }
}
</style>